//
//  HDCFMineViewController.m
//  HaoDeCaiFu
//
//  Created by 郑开宏 on 2017/10/28.
//  Copyright © 2017年 郑开宏. All rights reserved.
//

#import "HDCFMineViewController.h"
#import "UINavigationBar+Awesome.h"
#import "HDCFAlreadyHaveCell.h"
#import "HDCFMycolecFundVc.h"
#import "HDCFMyTradeHistoryVc.h"
#import "HDCFLoginView.h"
#import "HDCFLoginVc.h"
#import "HDCFRegisterVc.h"
#import "HDCFAccountSetVc.h"
#import "SVProgressHUD.h"
#import "HDCFFundDetailVc.h"
#import "HDCFRecommendViewController.h"
#import "WalletView.h"
#import "investProjectViewController.h"
#import "DingtouManagerTableViewController.h"
#import "MJRefresh.h"
#import "WalletViewController.h"
#import "ShoppingJifenViewController.h"

   
#define KPersonalInfo @"/public/investor/get-investor-info"
#define KMyProperty @"/public/transaction/get-holdings-statistic"
#define KMyPropertyList @"/public/transaction/get-investor-holdings"
#define kIHave @"/public/transaction/get-investor-holdings"

@interface HDCFMineViewController ()<UITableViewDelegate, UITableViewDataSource, HDCFLoginVcDelegate, HDCFAccountSetVcDelegate, UIScrollViewDelegate>

@property (nonatomic, weak) UIScrollView *mainScrollView;
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, weak) HDCFLoginView *loginView;
@property (nonatomic, weak) UILabel *allMoneyLable;
@property (nonatomic, weak) UILabel *yesterdayEarn;
@property (nonatomic, weak) UILabel *allEarnLabel;
@property (nonatomic, strong) NSMutableArray *myHaveFund;
@property (nonatomic, strong) WalletView *wallet;
@property (nonatomic,strong) NSDictionary *walletDic;
@end

@implementation HDCFMineViewController

- (NSMutableArray *)myHaveFund{
    if (!_myHaveFund) {
        self.myHaveFund = [NSMutableArray array];
    }
    return _myHaveFund;
}

//主要为了获取风险评测信息
- (void)getMineInfo{
    NSMutableDictionary *paramets = [NSMutableDictionary dictionary];
    paramets[@"accountNumber"] = kAcount;
    NSString *jsonStr = [self dictionaryToJson:paramets];
    NSDictionary *paramet = @{KparametOne:jsonStr,
                              KparametTwo:KPersonalInfo};
    
    [HttpRequest sendGetRequestWithURL:nil WithParamets:paramet success:^(id result) {
        NSString *code = result[@"code"];
        if ([code isEqualToString:@"0000"]) {
            NSDictionary *dataDict = result[@"data"];
            NSNumber *riskRating = dataDict[@"riskAppetite"];
            if (riskRating.integerValue > 0) {
                NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
                [user setValue:riskRating forKey:@"riskRating"];
                [user synchronize];
            }
        }else{
            [SVProgressHUD showErrorWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.0];
        }
        
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}


- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor whiteColor];
    self.automaticallyAdjustsScrollViewInsets = NO;
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
    [self.navigationItem setTitle:@"我的资产"];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    
    
    UIButton*rightBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    rightBtn.frame=CGRectMake(screenWidth-W_RATIO(150)-10, W_RATIO(50), W_RATIO(150), W_RATIO(60));
    [rightBtn setTitle:@"我的积分" forState:UIControlStateNormal];
    [rightBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    rightBtn.titleLabel.font=[UIFont systemFontOfSize:14];
    [rightBtn addTarget:self action:@selector(rightBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem*rightBarBtnItem=[[UIBarButtonItem alloc]initWithCustomView:rightBtn];
    self.navigationItem.rightBarButtonItem=rightBarBtnItem;
   
    
    
    [self.view addSubview:self.tableView];
    [self.tableView setTableHeaderView:[self creatView]];
    
//    [self creatView];
    [self setV];
    
    
    
}

-(void)rightBtnClick:(UIButton*)btn
{
    [self isLogin];
    ShoppingJifenViewController*vc=[[ShoppingJifenViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
    NSLog(@"6666");
}


- (NSString *)dictionaryToJson:(NSDictionary *)dic{
    NSError *error = nil;
    NSData *jsonData = [NSJSONSerialization dataWithJSONObject:dic options:NSJSONWritingPrettyPrinted error:&error];
    return [[NSString alloc] initWithData:jsonData encoding:NSUTF8StringEncoding];
}

- (void)getMyProperty{
    NSMutableDictionary *paramets = [NSMutableDictionary dictionary];
    
    paramets[@"accountNumber"] = kAcount;
    NSString *jsonStr = [self dictionaryToJson:paramets];
    NSDictionary *paramet = @{KparametOne:jsonStr,
                              KparametTwo:KMyProperty};
    [SVProgressHUD show];
    [HttpRequest sendGetRequestWithURL:nil WithParamets:paramet success:^(id result) {
        [SVProgressHUD dismiss];
        NSString *code = result[@"code"];
        [self.tableView.mj_header endRefreshing];
        if ([code isEqualToString:@"0000"]) {
            NSDictionary *dict = result[@"data"];
            NSNumber *allMoney = dict[@"currentAmount"];
            if ([allMoney isKindOfClass:[NSNull class]]) {
                self.allMoneyLable.text = @"0.00";
            }else{
                self.allMoneyLable.text = [NSString stringWithFormat:@"%.2f", allMoney.doubleValue];
            }
            NSNumber *historyEarn = dict[@"accumulatedProfitLoss"];
            if ([historyEarn isKindOfClass:[NSNull class]]) {
                self.allEarnLabel.text = @"0.00\n累计收益(元)";
            }else{
                self.allEarnLabel.text = [NSString stringWithFormat:@"%.2f\n累计收益(元)", historyEarn.doubleValue];
            }
            
            NSNumber *profitLossDaily = dict[@"profitLossDaily"];
            if ([profitLossDaily isKindOfClass:[NSNull class]]) {
                self.yesterdayEarn.text = @"0.00\n昨日收益(元)";
            }else{
                self.yesterdayEarn.text = [NSString stringWithFormat:@"%.2f\n昨日收益(元)", profitLossDaily.doubleValue];
            }
            
        }else{
            [SVProgressHUD showErrorWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.0];
        }
        
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];

}


- (void)getMyWalltInfo{
    NSMutableDictionary *paramets = [NSMutableDictionary dictionary];
    
    paramets[@"accountNumber"] = kAcount;
    NSString *jsonStr = [self dictionaryToJson:paramets];
    NSDictionary *paramet = @{KparametOne:jsonStr,
                              KparametTwo:@"/public/wallet/get-cash-wallet-holdings"};
     [SVProgressHUD show];
    [HttpRequest sendGetRequestWithURL:nil WithParamets:paramet success:^(id result) {
        NSString *code = result[@"code"];
        [self.tableView.mj_header endRefreshing];
        if ([code isEqualToString:@"0000"]) {
             NSDictionary *dataDic = result[@"data"];
            NSArray *dataArray = dataDic[@"data"];
            for (NSDictionary*dic in dataArray) {
                self.walletDic=dic;
                self.wallet.xianzhiLable.text=[NSString stringWithFormat:@"%.2f元",[dic[@"totalCurrentValue"] floatValue]];
                self.wallet.lastDayShouyiLable.text=[NSString stringWithFormat:@"%.2f",[dic[@"preProfitLoss"] floatValue]];
            }
            [SVProgressHUD dismiss];
        }else{
            [SVProgressHUD showErrorWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.0];
        }
        
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
    
}

//已持有数据
- (void)getMyHaven{
    NSMutableDictionary *paramets = [NSMutableDictionary dictionary];
    paramets[@"accountNumber"] = kAcount;
    NSString *jsonStr = [self dictionaryToJson:paramets];
    NSDictionary *paramet = @{KparametOne:jsonStr,
                              KparametTwo:kIHave};
    [HttpRequest sendGetRequestWithURL:nil WithParamets:paramet success:^(id result) {
        LLLog(@"%@",result);
        NSString *code = result[@"code"];
        [self.tableView.mj_header endRefreshing];
        if ([code isEqualToString:@"0000"]) {
            [self.myHaveFund removeAllObjects];
            NSDictionary *dict = result[@"data"];
            NSArray *array = [NSArray arrayWithArray:dict[@"data"]];
            if (array.count > 0) {
                for (int i = 0; i < array.count; i++) {
                    NSDictionary *dictTwo = array[i];
                    if ([dictTwo[@"portfolioName"] isEqualToString:@"个别投资项目"]) {
                        NSDictionary *dictThree = dictTwo[@"fundHoldings"];
                        if (![dictThree isEqual:[NSNull null]]&&dictThree) {
                             [self.myHaveFund addObjectsFromArray:dictThree[@"data"]];
                        }
                        
                       
                        
                    }else{
                        [self.myHaveFund addObject:dictTwo];
                    }
                }
                [self.tableView reloadData];
            }
        }else{
            [SVProgressHUD showInfoWithStatus:result[@"message"]];
            [SVProgressHUD dismissWithDelay:1.0];
        }
    } failure:^(NSError *errer) {
        [SVProgressHUD showErrorWithStatus:@"网络错误"];
        [SVProgressHUD dismissWithDelay:1.0];
    }];
}

- (void)getMyPropertyList{
    NSMutableDictionary *paramets = [NSMutableDictionary dictionary];
    paramets[@"accountNumber"] = kAcount;
    NSString *jsonStr = [self dictionaryToJson:paramets];
    NSDictionary *paramet = @{KparametOne:jsonStr,
                              KparametTwo:KMyPropertyList};
    
    [HttpRequest sendGetRequestWithURL:nil WithParamets:paramet success:^(id result) {
        
        NSString *code = result[@"code"];
        if ([code isEqualToString:@"0000"]) {
            
        }else{
            
        }
        
    } failure:^(NSError *errer) {
        
    }];
    
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    NSString *openStatus = kOpenStatus;
    if (openStatus.integerValue > 0){
        
    }else{
        self.allMoneyLable.text = @"0.00";
        self.allEarnLabel.text = @"0.00\n累计收益(元)";
        self.yesterdayEarn.text = @"0.00\n昨日收益(元)";
        self.wallet.xianzhiLable.text=@"0.00元";
//        self.wallet.shouyiLable.text=@"+0.00元";
        self.wallet.lastDayShouyiLable.text=@"+0元";
    }
    if (!kToken) {
        if (!_loginView) {
            HDCFLoginView *loginView = [HDCFLoginView HDCFLoginView];
            self.loginView = loginView;
            [loginView.registerBtn addTarget:self action:@selector(register) forControlEvents:UIControlEventTouchUpInside];
            [loginView.loginBtn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
            loginView.frame = CGRectMake(0, 0, screenWidth, 200);
            [self.tableView addSubview:loginView];
        }
    }else{
        if (self.loginView) {
            [self.loginView removeFromSuperview];
        }
    }
    
    NSString *accountNumber = kAcount;
    if (accountNumber.length > 1) {
         NSString *openStatus = kOpenStatus;
        if (openStatus.integerValue > 0)
        {
            [self getMyHaven];
            [self getMyProperty];
            [self getMyWalltInfo];
            
            if (!kRiskResult)
            {
                [self getMineInfo];
            }
        }
    }
    
    self.navigationController.navigationBarHidden = NO;
    
    self.navigationController.navigationBar.translucent = YES;
    [self.navigationController.navigationBar setShadowImage:[UIImage new]];
      [self.navigationController.navigationBar lt_setBackgroundColor:[UIColor clearColor]];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
}

- (void)setV{
    if (@available(iOS 11.0, *))
    {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    } else {
        // Fallback on earlier versions
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

- (void)headRefresh{
    NSString *accountNumber = kAcount;
    if (accountNumber.length > 1) {
        NSString *openStatus = kOpenStatus;
        if (openStatus.integerValue > 0){
            [self getMyHaven];
            [self getMyProperty];
            if (!kRiskResult) {
                [self getMineInfo];
                [self getMyProperty];
            }
        }else{
            [self.tableView.mj_header endRefreshing];
        }
    }else{
        [self.tableView.mj_header endRefreshing];
    }
}

- (UIView*)creatView{

//    UIScrollView *mainScrollView = [[UIScrollView alloc] init];
//    mainScrollView.delegate = self;
//    self.mainScrollView = mainScrollView;
//    mainScrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headRefresh)];
//    mainScrollView.mj_header = [MJRefreshNormalHeader headerWithRefreshingBlock:^{
//        NSString *accountNumber = kAcount;
//        if (!(self.myHaveFund.count > 0) && accountNumber.length > 1) {
//            NSString *openStatus = kOpenStatus;
//            if (openStatus.integerValue > 0){
//                [self getMyHaven];
//                 [self getMyProperty];
//                if (!kRiskResult) {
//                    [self getMineInfo];
//                }
//            }
//        }
//
//    }];
    //调整页面位置
//    [self setV];
//    mainScrollView.bounces = YES;
//    mainScrollView.frame = CGRectMake(0, 0, screenWidth, screenHeight);
//    mainScrollView.contentSize = CGSizeMake(screenWidth, screenHeight + 1);
//    mainScrollView.showsVerticalScrollIndicator = NO;
//    mainScrollView.showsHorizontalScrollIndicator = NO;
//    mainScrollView.backgroundColor = [UIColor whiteColor];
//    [self.view addSubview:mainScrollView];
    
    
    UIView*headerView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, screenWidth, 530)];
    headerView.backgroundColor=[UIColor whiteColor];
    
    
    UIImageView *imageView = [[UIImageView alloc] init];
    imageView.frame = CGRectMake(0, 0, screenWidth, 200);
    imageView.image = [UIImage imageNamed:@"bg"];
    [headerView addSubview:imageView];
    
    UILabel *allMoney = [[UILabel alloc] init];
    allMoney.frame = CGRectMake(0, KNavHeight + 10, screenWidth, 21);
    allMoney.text = @"总资产（元）";
    allMoney.textColor = [UIColor whiteColor];
    allMoney.textAlignment = NSTextAlignmentCenter;
    allMoney.font = [UIFont systemFontOfSize:17];
    [headerView addSubview:allMoney];
    
    UILabel *allMoneyNumber = [[UILabel alloc] init];
    self.allMoneyLable = allMoneyNumber;
    allMoneyNumber.frame = CGRectMake(0, CGRectGetMaxY(allMoney.frame) + 5, screenWidth, 25);
    allMoneyNumber.text = @"0.00";
    allMoneyNumber.textColor = [UIColor whiteColor];
    allMoneyNumber.textAlignment = NSTextAlignmentCenter;
    allMoneyNumber.font = [UIFont boldSystemFontOfSize:20];
    [headerView addSubview:allMoneyNumber];
    
    
    UILabel *yesterdayEarn = [[UILabel alloc] init];
    self.yesterdayEarn = yesterdayEarn;
    yesterdayEarn.frame = CGRectMake(0, imageView.height - 55, screenWidth / 2 - 1 , 50);
    yesterdayEarn.numberOfLines = 0;
    NSString *strleft = @"0.00\n昨日收益(元)";
    NSMutableAttributedString *attrStr = [[NSMutableAttributedString alloc] initWithString:strleft];
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont boldSystemFontOfSize:17]
                    range:NSMakeRange(0, strleft.length - 8)];
    [attrStr addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:16]
                    range:NSMakeRange(strleft.length - 8, 8)];
    [attrStr addAttribute:NSForegroundColorAttributeName
                    value:[UIColor whiteColor]
                    range:NSMakeRange(0, strleft.length)];
    yesterdayEarn.textColor = [UIColor whiteColor];
    yesterdayEarn.attributedText = attrStr;
    yesterdayEarn.textAlignment = NSTextAlignmentCenter;
//    yesterdayEarn.font = [UIFont systemFontOfSize:17];
    [headerView addSubview:yesterdayEarn];
    
    UIView *sliderView = [[UIView alloc] init];
    sliderView.frame = CGRectMake(screenWidth / 2 - 1, imageView.height - 50, 1, 45);
    sliderView.backgroundColor = ZKcolor(255, 184, 155);
    [headerView addSubview:sliderView];
    
    
    UILabel *allEarn = [[UILabel alloc] init];
    self.allEarnLabel = allEarn;
    allEarn.frame = CGRectMake(screenWidth / 2, imageView.height - 55, screenWidth / 2 - 1 , 50);
    allEarn.numberOfLines = 0;
    NSString *strRight = @"0.00\n累计收益(元)";
    NSMutableAttributedString *attrStrT = [[NSMutableAttributedString alloc] initWithString:strRight];
    [attrStrT addAttribute:NSFontAttributeName
                    value:[UIFont boldSystemFontOfSize:17]
                    range:NSMakeRange(0, strleft.length - 8)];
    [attrStrT addAttribute:NSFontAttributeName
                    value:[UIFont systemFontOfSize:16]
                    range:NSMakeRange(strleft.length - 8, 8)];
    [attrStrT addAttribute:NSForegroundColorAttributeName
                    value:[UIColor whiteColor]
                    range:NSMakeRange(0, strleft.length)];
    allEarn.textColor = [UIColor whiteColor];
    allEarn.attributedText = attrStrT;
    allEarn.textAlignment = NSTextAlignmentCenter;
    [headerView addSubview:allEarn];
    
    HDCFLoginView *loginView = [HDCFLoginView HDCFLoginView];
    self.loginView = loginView;
    [loginView.registerBtn addTarget:self action:@selector(register) forControlEvents:UIControlEventTouchUpInside];
    [loginView.loginBtn addTarget:self action:@selector(login) forControlEvents:UIControlEventTouchUpInside];
    loginView.frame = CGRectMake(0, 0, screenWidth, 200);
    if (!kToken) {
        [headerView addSubview:loginView];
    }
    
    NSArray *titleAry = [NSArray arrayWithObjects:@"收藏夹", @"交易记录", @"我的推荐", @"账户设置", nil];
    NSArray *imgUrl = [NSArray arrayWithObjects:@"icon_shoucang", @"icon_jilu", @"icon_tuijian", @"icon_zhanghu", nil];
    CGFloat btnWidth = (screenWidth - 3) / 4;
    CGFloat btnHeight = btnWidth + 10;
    CGFloat btnY = CGRectGetMaxY(imageView.frame);
    for (int i = 0; i < 4; i++) {
        NSString *title = titleAry[i];
        NSString *imgName = imgUrl[i];
        UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
        [btn setTitleColor:ZKcolor(187, 187, 187) forState:UIControlStateNormal];
        [btn.titleLabel setFont:[UIFont systemFontOfSize:14]];
        [btn setTitle:title forState:UIControlStateNormal];
        btn.tag = 100 + i;
        [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
        [btn setImage:[UIImage imageNamed:imgName] forState:UIControlStateNormal];
        btn.x = i * (btnWidth + 1);
        btn.y = btnY;
        
        btn.size = CGSizeMake(btnWidth, btnHeight);
        
        btn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
        [btn setTitleEdgeInsets:UIEdgeInsetsMake(btn.imageView.frame.size.height + 5 ,-btn.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度，距离左边框减少imageView的宽度，距离下边框和右边框距离不变
        [btn setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0,btn.titleLabel.frame.size.height + 5, -btn.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度，其它不边
        
        [headerView addSubview:btn];
    }
    
    for (int i = 0; i < 3; i++) {
        UIView *sl = [[UIView alloc] init];
        sl.x = (i + 1) * btnWidth + i * 1;
        sl.backgroundColor = ZKcolor(245, 245, 245);
        sl.y = btnY;
        sl.size = CGSizeMake(1, btnHeight);
        [headerView addSubview:sl];
    }
    
    UIView *sld = [[UIView alloc] init];
    sld.backgroundColor = ZKcolor(245, 245, 245);;
    sld.frame = CGRectMake(0, btnY + btnHeight, screenWidth, 1);
    [headerView addSubview:sld];
    
    
    self.wallet=[WalletView fixTrowSetView];
    _wallet.frame=CGRectMake(10, CGRectGetMaxY(sld.frame)+10, screenWidth-20, 100);
    _wallet.backgroundColor=[UIColor whiteColor];
    _wallet.clipsToBounds=YES;
    _wallet.layer.cornerRadius=5;
    _wallet.layer.borderColor=ZKcolor(240, 240, 240).CGColor;
    _wallet.layer.borderWidth=0.5;
    _wallet.backgroundColor=[UIColor whiteColor];
    [headerView addSubview:_wallet];
    UITapGestureRecognizer *tap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(WalletViewTap:)];
    [_wallet addGestureRecognizer:tap];
    
    
    
    UIView*myDingtouView=[[UIView alloc]initWithFrame:CGRectMake(-10, _wallet.bottom+10, screenWidth, 60)];
    myDingtouView.backgroundColor=[UIColor whiteColor];
    myDingtouView.layer.borderColor=ZKcolor(240, 240 , 240).CGColor;
    myDingtouView.layer.borderWidth=0.5;
    [headerView addSubview:myDingtouView];
    
    UIButton*dingtouBtn=[UIButton buttonWithType:UIButtonTypeCustom];
    dingtouBtn.frame=CGRectMake(20, 10, screenWidth-20, 40);
    [dingtouBtn setImage:[UIImage imageNamed:@"icon_edu"] forState:UIControlStateNormal];
    [dingtouBtn setTitle:@"   定投管理" forState:UIControlStateNormal];
    [dingtouBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    dingtouBtn.titleLabel.font=[UIFont systemFontOfSize:15];
    [dingtouBtn addTarget:self action:@selector(dingtouBtnClick:) forControlEvents:UIControlEventTouchUpInside];
    dingtouBtn.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
    [myDingtouView addSubview:dingtouBtn];
    
    
    
    
    
    UIImageView *imageTwo = [[UIImageView alloc] init];
    imageTwo.image = [UIImage imageNamed:@"yichiyou"];
    imageTwo.frame = CGRectMake(10, CGRectGetMaxY(myDingtouView.frame) + 10 , 11, 24);
    [headerView addSubview:imageTwo];
    
    UILabel *haveL = [[UILabel alloc] init];
    haveL.frame = CGRectMake(25,imageTwo.top , 80, 24);
    haveL.text = @"已持有";
    haveL.textColor = ZKcolor(30, 30, 30);
    haveL.textAlignment = NSTextAlignmentCenter;
    haveL.font = [UIFont systemFontOfSize:15];
    [headerView addSubview:haveL];
    
    UIView *sldTwo = [[UIView alloc] init];
    sldTwo.backgroundColor = ZKcolor(245, 245, 245);
    sldTwo.frame = CGRectMake(0, haveL.bottom+5, screenWidth, 1);
    [headerView addSubview:sldTwo];
    
    
    return headerView;
    
   
}


-(UITableView*)tableView
{
    if (!_tableView) {
        CGRect tableFrame = CGRectMake(0, 0, screenWidth, screenHeight - 49);
        _tableView=[[UITableView alloc]initWithFrame:tableFrame];
        _tableView.separatorColor = ZKcolor(245, 245, 245);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.mj_header = [MJRefreshNormalHeader headerWithRefreshingTarget:self refreshingAction:@selector(headRefresh)];
        _tableView.tableFooterView = [[UIView alloc] initWithFrame:CGRectZero];
       
    }
    return _tableView;
}

-(void)WalletViewTap:(UIGestureRecognizer*)gesture
{
    [self isLogin];
    
    NSString *openStatus = kOpenStatus;
    if (!(openStatus.integerValue > 0)){
        [SVProgressHUD showInfoWithStatus:@"请先开户"];
        [SVProgressHUD dismissWithDelay:1.0];
        return;
    }
    
    WalletViewController*vc=[[WalletViewController alloc]init];
    vc.walletDic=self.walletDic;
    [self.navigationController pushViewController:vc animated:YES];
}

-(void)dingtouBtnClick:(UIButton*)btn
{
    [self isLogin];
    NSString *openStatus = kOpenStatus;
    if (!(openStatus.integerValue > 0)){
        [SVProgressHUD showInfoWithStatus:@"请先开户"];
        [SVProgressHUD dismissWithDelay:1.0];
        return;
    }
    DingtouManagerTableViewController*vc=[[DingtouManagerTableViewController alloc]init];
    [self.navigationController pushViewController: vc animated:YES];
}


-(void)isLogin
{
    if (!kToken) {
        UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"提示" message:@"您还未登录！请先登录" preferredStyle:UIAlertControllerStyleAlert];
        UIAlertAction *action1 = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            HDCFLoginVc *vc = [[HDCFLoginVc alloc] init];
            vc.delegate = self;
            [self.navigationController pushViewController:vc animated:YES];
        }];
        UIAlertAction * action2 = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
            
        }];
        [alert addAction: action1];
        [alert addAction: action2];
        [self presentViewController:alert animated:NO completion:nil];
        return;
    }
}

- (void)btnClick:(UIButton *)btn{
    
    [self isLogin];
    if (btn.tag == 100) {
        HDCFMycolecFundVc *vc = [[HDCFMycolecFundVc alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (btn.tag == 101){
        NSString *openStatus = kOpenStatus;
        if (!(openStatus.integerValue > 0)){
            [SVProgressHUD showInfoWithStatus:@"请先开户"];
            [SVProgressHUD dismissWithDelay:1.0];
            return;
        }
        HDCFMyTradeHistoryVc *vc = [[HDCFMyTradeHistoryVc alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (btn.tag == 102){
        HDCFRecommendViewController *vc = [[HDCFRecommendViewController alloc] init];
        [self.navigationController pushViewController:vc animated:YES];
    }else if (btn.tag == 103){
        HDCFAccountSetVc *vc = [[HDCFAccountSetVc alloc] init];
        vc.delegate = self;
        [self.navigationController pushViewController:vc animated:YES];
    }
}

- (void)quitSucess{
    [self.myHaveFund removeAllObjects];
    [self.tableView reloadData];
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.myHaveFund.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 89;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    
    static NSString *cellID = @"CELLID";
    HDCFAlreadyHaveCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [HDCFAlreadyHaveCell HDCFAlreadyHaveCell];
    }
    NSDictionary *dict = self.myHaveFund[indexPath.row];
    cell.dataDict = dict;
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    cell.preservesSuperviewLayoutMargins = NO;
    cell.separatorInset = UIEdgeInsetsZero;
    cell.layoutMargins = UIEdgeInsetsZero;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    investProjectViewController *detailVc = [[investProjectViewController alloc] init];
        NSDictionary *dict = self.myHaveFund[indexPath.row];
    if(dict[@"modelPortfolioCode"]&&![dict[@"modelPortfolioCode"] isEqual:[NSNull null]]){
        detailVc.zichanType=1;
        detailVc.code=dict[@"portfolioId"];
         detailVc.titleStr=dict[@"portfolioName"];
    }
    else
    {
        detailVc.titleStr=dict[@"fundName"];
        if ([dict[@"fundType"]isEqualToString:@"fund"]) {
         detailVc.zichanType=2;
        }
        else if ([dict[@"fundType"]isEqualToString:@"collective"])
        {
        detailVc.zichanType=3;
        }
        detailVc.chargeMode=dict[@"chargeMode"];
        detailVc.code=dict[@"fundCode"];
    }
    
    [self.navigationController pushViewController:detailVc animated:YES];
}


- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    [self.navigationController.navigationBar lt_reset];
    
}

- (void)register{
    HDCFRegisterVc *vc = [[HDCFRegisterVc alloc] init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)login{
    HDCFLoginVc *vc = [[HDCFLoginVc alloc] init];
    vc.delegate = self;
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)loginSucess{
    [self.loginView removeFromSuperview];
}

@end
